package com.lotea.android.andreaditlater.io;

import org.apache.http.Header;
import org.apache.http.HttpResponse;

public class APIResponse {
	private int status;
	private String errorMessage;
	private int userLimit;
	private int userRemaining;
	private int userReset;
	private int keyLimit;
	private int keyRemaining;
	private int keyReset;
	private String data;

	public APIResponse(HttpResponse response) {
		status = response.getStatusLine().getStatusCode();

		final Header error = response.getFirstHeader(API.Headers.ERROR);
		final Header userLimit = response
				.getFirstHeader(API.Headers.USER_LIMIT);
		final Header userRemaining = response
				.getFirstHeader(API.Headers.USER_REMAINING);
		final Header userReset = response
				.getFirstHeader(API.Headers.USER_RESET);
		final Header keyLimit = response.getFirstHeader(API.Headers.KEY_LIMIT);
		final Header keyRemaining = response
				.getFirstHeader(API.Headers.KEY_REMAINING);
		final Header keyReset = response.getFirstHeader(API.Headers.KEY_RESET);

		this.errorMessage = error != null ? error.getValue() : "";

		this.userLimit = userLimit != null ? Integer.parseInt(userLimit
				.getValue()) : 0;
		this.userRemaining = userRemaining != null ? Integer
				.parseInt(userRemaining.getValue()) : 0;
		this.userReset = userReset != null ? Integer.parseInt(userReset
				.getValue()) : 0;

		this.keyLimit = keyLimit != null ? Integer
				.parseInt(keyLimit.getValue()) : 0;
		this.keyRemaining = keyRemaining != null ? Integer
				.parseInt(keyRemaining.getValue()) : 0;
		this.keyReset = keyReset != null ? Integer
				.parseInt(keyReset.getValue()) : 0;
	}

	/**
	 * @return the data
	 */
	public String getData() {
		return data;
	}

	/**
	 * @param data the data to set
	 */
	public void setData(String data) {
		this.data = data;
	}

	/**
	 * @return the status
	 */
	public int getStatus() {
		return status;
	}

	/**
	 * @return the errorMessage
	 */
	public String getErrorMessage() {
		return errorMessage;
	}

	/**
	 * @return the userLimit
	 */
	public int getUserLimit() {
		return userLimit;
	}

	/**
	 * @return the userRemaining
	 */
	public int getUserRemaining() {
		return userRemaining;
	}

	/**
	 * @return the userReset
	 */
	public int getUserReset() {
		return userReset;
	}

	/**
	 * @return the keyLimit
	 */
	public int getKeyLimit() {
		return keyLimit;
	}

	/**
	 * @return the keyRemaining
	 */
	public int getKeyRemaining() {
		return keyRemaining;
	}

	/**
	 * @return the keyReset
	 */
	public int getKeyReset() {
		return keyReset;
	}
}